

function reverseList(head){
    let pre = null
    while(head){
        let next = head.next;
        head.next = pre
        pre = head;
        head = next; // 保证pre 是当前haed
    }
    return pre
}


// 链表的基本机构
function ListNode(val) {
    this.name = val;
    this.next = null;  // 一般是下一个的指针 最后一个为null
}

var a = new ListNode(1);
var b = new ListNode(2);
var c = new ListNode(3);
a.next = b;
b.next = c;

let head = a;
while (head) {
    console.log("转换前", head.name);
    head = head.next
}

head = reverseList(a);

while (head) {
    console.log("转换后", head.name);
    head = head.next
}